package ru.tennisworld.user.entities;

import jakarta.persistence.AttributeOverride;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.PrimaryKeyJoinColumn;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import ru.tennisworld.user.entities.base.BaseEntity;

import java.util.Collection;

@Data
@Entity
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false)
@AttributeOverride(name = "id", column = @Column(name = "TENNIS_USER_ID"))
@SequenceGenerator(sequenceName = "TENNIS_USER_ID_SEQ", name = "seq_gen",
        initialValue = 1000, allocationSize = 1)
@Table(name = "TENNIS_USERS")
public class TennisUser extends BaseEntity {

    @Column(name = "LOGIN")
    private String login;

    @Column(name = "PASSWORD")
    private String password;

    @OneToOne(mappedBy = "tennisUser", cascade = {CascadeType.ALL})
    @PrimaryKeyJoinColumn
    private TennisUserProfile tennisUserProfile;

    @ManyToMany
    @JoinTable(
            name = "TENNIS_USERS_TENNIS_ROLES",
            joinColumns = @JoinColumn(name = "TENNIS_USER_ID"),
            inverseJoinColumns = @JoinColumn(name = "TENNIS_USER_ROLE_ID")
    )
    private Collection<TennisUserRole> userRoles;
}
